<%--
  Created by IntelliJ IDEA.
  User: Albert Lee
  Date: 2020/5/26
  Time: 16:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ page import="java.sql.*" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>按id搜索</title>
</head>
<link rel="stylesheet" href="css/header.css">


<body background="resourse/bg.jpg">
<%--判断是否登录--%>
<%
    String userid=(String)session.getAttribute("userid");
//    System.out.print("Session userID="+userid);

    if (userid!=null) {
%>

<!--页头-->
<div id="header">
    <spana>&emsp;巴以小记</spana>
    <br>
    <spanb>&emsp;&emsp;<%=(String)session.getAttribute("userid")%> 在线中..</spanb>
    <ul>
        <li></li>
        <li><h2 class="main" ><a class="btna" href="main.jsp">主页</a></h2></li>
        <li><h2 class="work"><a class="btna" href="addInfo.jsp">发贴</a></h2></li>
        <li><h2 class="new"><a class="btna" href="showInfo.jsp" >看贴</a></h2></li>
        <li><h2 class="comment"><a class="btna" href="showInfo.jsp" >搜索</a></h2></li>
    </ul>
</div>
<br>

     <%
        request.setCharacterEncoding("UTF-8");
        String id = request.getParameter("id");
        Connection conn = null;
        Statement stat = null;
        ResultSet rs = null;
        Class.forName("com.mysql.cj.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/talknewsdatabase";
        String user = "root";
        String password = "123456";
        conn = DriverManager.getConnection(url, user, password);
        stat = conn.createStatement();
        rs = stat.executeQuery("select * from info where user_id='" +userid +  "' and id=" + id + "");

    %>


<center>
    <table cellSpacing=1 >
        <%
            if (rs.next()) {
                out.print("<tr><th colspan=\"3\"><h3  align=\"center\" ><strong>" + rs.getString("title") + "</strong></h3></th></tr>");

                out.print("<tr><td  align=\"center\"> 编号：" + rs.getString("id") + "</td>");
                out.print("<td  align=\"center\"> 类型：" + rs.getString("name") + "</td> <td></td>");

                out.print("<tr><td colspan=\"3\" align=\"center\"> <textarea readonly rows=\"20\" cols=\"90\" style=\"font-size:20px;\">"+rs.getString("comment")+"</textarea></td></tr>");
        %>
        <tr>
            <td  align="center"><a href="delete.jsp?id=<%=rs.getString("id") %>">删除</a></td>
            <td  align="center"><a href="update.jsp?id=<%=rs.getString("id") %>">修改</a></td>
            <td  align="center"><a href="showInfo.jsp">返回信息页</a></td>
        </tr>
        <%
            } else {
                out.print("<script>alert('不存在此信息！');" +
                        "window.location='http://localhost:8080/showInfo.jsp';</script>");
            }
        %>  
    </table>
</center>


     <%
        if (rs != null) {
            rs.close();
            rs = null;
        }

        if (stat != null) {
            stat.close();
            stat = null;
        }

        if (conn != null) {
            conn.close();
            conn = null;
        }

    %>

<%
    } else {
        out.print("<script>alert('未成功登录！');" +
                "window.location='http://localhost:8080/index.html';</script>");
    }
%>  

</body>
</html>